<!DOCTYPE html>
<html>
<head>
    <title>微信支付</title>
</head>
<body>
<script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script type="text/javascript">
        var out_trade_no = "{$out_trade_no}";
        (function(x){
           if (typeof WeixinJSBridge == "undefined"){
                if( document.addEventListener ){
                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                }else if (document.attachEvent){
                    document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                }
            }else{
                jsApiCall();
            }
            
            function jsApiCall(){
               var sign = "{$sign}";
               var out_trade_no = "{$out_trade_no}";
                var  options = '{$options}';
                     options =JSON.parse(options);
                WeixinJSBridge.invoke(
                    'getBrandWCPayRequest',options ,
                     function(res){
                        if(res.err_msg == "get_brand_wcpay_request:ok"){
                            if(sign == 1){
                                window.location.href="{:url('PayComplete/get_coupon')}?out_trade_no="+out_trade_no;
                            }else if(sign == 2){        //会员充值
                                window.location.href="{:url('User/user_credit_log')}";
                            }else if(sign == 3){
                                window.location.href="{:url('User/my_coupon')}";
                            }
                        }else{
                            alert('支付失败');
                            window.location.href="{:url('User/index')}";
                        }
//                        alert(JSON.stringify(res));
                        // WeixinJSBridge.log(res.err_msg);
                        // alert(res.err_code+res.err_desc+res.err_msg);
                    }
                );
            }
        })(document.body)
    </script>
<script type="text/javascript">

</script>
</body>
</html>